# encoding: utf-8

from django.contrib.syndication.feeds import Feed
from models import Domain
from models import Supermaster
from models import Record
from models import Nameserver
from django.core.exceptions import ObjectDoesNotExist
from django.utils.feedgenerator import Atom1Feed



class LatestEntries(Feed):

#	def get_absolute_url(self):
#		return "/feeds/rss/latest"
#		
#	def title(self):
#		return "title"
#		
#	def link(self):
#		return self.get_absolute_url()
#		
#	def description(self):
#		return "description"

	title="latest changes"
	link="/feeds/rss/latest"
	description="latest changed records"
		
	def items(self):
		records = Record.objects.all()
		return records.order_by('-id')[:100]
		
		
class AtomLatestEntries(LatestEntries):
	feed_type = Atom1Feed
	def get_absolute_url(self):
		return "/feeds/atom/latest"
		
class DomainFeed(Feed):
	def get_object(self, bits):
		if len(bits) != 1:
			raise ObjectDoesNotExist
		return Domain.objects.get(id=bits[0])
	
	def title(self, obj):
		return "Latest DNS Changes for Domain %s" % obj.name
		
	def link(self, obj):
		return obj.get_absolute_url()
		
	def description(self, obj):
		return "These changes in our Domain Name Service Database was recently made for Domain %s" % obj.name
	
	def items(self, obj):
		records = Record.objects.filter(domain=obj.id)
		return records.order_by("-id")[:30]
		
class AtomDomainFeed(DomainFeed):
	feed_type = Atom1Feed
